package com.cxm.homework9.anno;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

public class UserDaoImpl implements UserDao {
    private JdbcTemplate jdbcTemplate;
    public void setJdbcTemplate(JdbcTemplate jdbcTemplate){
        this.jdbcTemplate=jdbcTemplate;
    }

    @Transactional(propagation = Propagation.REQUIRED,isolation = Isolation.DEFAULT,readOnly = false)
    @Override
    public void transfer(String userName1, String userName2, int money) {
        jdbcTemplate.update("update user set balance=balance-? where username=?",money,userName1);
        int i=1/0;
        jdbcTemplate.update("update user set balance=balance+? where username=?",money,userName2);
        System.out.println("转账成功");
    }
}
